// src/router/index.js
import Vue from 'vue'
import Router from 'vue-router' // 改为 Router
import tree from './modules/tree'
import employee from './modules/employee'
import role from './modules/role'
import power from './modules/power'
import Layout from '@/layout'

Vue.use(Router)

// 1. 定义基础路由
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    children: [
      {
        path: 'dashboard',
        name: 'Dashboard',
        component: () => import('@/views/dashboard/index'),
        meta: { title: 'Dashboard', icon: 'dashboard' }
      }
    ]
  },
  tree,
  role,
  employee,

  power,
  { path: '*', redirect: '/404', hidden: true }
]

// 2. 创建路由实例的方法
const createRouter = () =>
  new Router({
    mode: 'history', // 使用 history 模式
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
  })

// 3. 创建路由实例
const router = createRouter()

// 4. 重置路由方法
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher
}

export default router
